<?php
global $_W,$_GPC;
$settings = $this->module['config'];
$index = intval($_GPC["index"]);
$keyword = trim($_GPC["keyword"]);
$cityid = intval($_GPC["cityid"]);
$cityCode = intval($_GPC["cityCode"]);
if(!$cityid){$cityid = 40;}
if(!$cityCode){$cityCode = 500100;}
$lng = $_GPC["lon"];
$lat = $_GPC["lat"];
$data = array("lat" => '', "lng" => '', "mode" => 'qmm', "app_key" => '', "domainName" => 'https://gw.taototo.cn/', "token" => '', "platformUUID" => '10000000', "latitude" => '', "longitude" => '', "cityId" => $cityid, "evnType" => 'h5', "envType" => 'h5', "ci" => $cityid, "cityCode" => $cityCode, "page" => 1, "limit" => '100', "showType" => '2');
$url = $settings['movie_h5_s_url2'] . "yp-api/movie/film/query";
$res = $this->geturl($url,$data);
if(count($res['data']['list']) > 0){
	$come = $res['data']['list'];
	$comeindex['type'] = 1;
	$comeindex['come'] = $come;
	exit(json_encode($comeindex));
}else{
	$time = time();
	$data = array("appKey" => $settings['movie_api_s_appKey'], "cityId" => $cityid, "time" => $time);
	$sign = $this->get_sign($data, $settings['movie_api_s_appSecret']);
	$data["sign"] = $sign;
	$url = $settings['movie_api_s_url2'] . "movieapi/movie-info/get-soon-list";
	$res = $this->geturl($url,$data);
	$come = $res["data"]['list'];
	$come = array_slice($come,0,10);
	$comeindex['type'] = 2;
	$comeindex['come'] = $come;
	exit(json_encode($comeindex));
}













if($index == 1){
	$time = time();
	$data = array("appKey" => $settings['movie_api_s_appKey'], "time" => $time);
	$sign = $this->get_sign($data, $settings['movie_api_s_appSecret']);
	$data["sign"] = $sign;
	$url = $settings['movie_api_s_url2'] . "movieapi/movie-info/get-hot-list";
	$res = $this->geturl($url,$data);
	if (!empty($keyword)) {
		$res["data"]['list'] = $this->search($res["data"]['list'], $keyword);
	}
	$hot = $res["data"]['list'];
	$c = 0;
	foreach($hot as $k=>$v){
		if(strtotime($v['publishDate'])<time()){
			$hot[$k]['status'] = 1;
		}else{
			$hot[$k]['status'] = 0;
			$indexcome[$c] = $v;
			$indexcome[$c]['status'] = 0;
			$c++;

		}
	}
	$hot = $hot;
	$hotshuliang = count($res["data"]['list']);
	$hotindex = array_slice($hot,0,10);
	$indexcomeshuliang = count($indexcome);
	$indexcome = array_slice($indexcome,0,10);
}


if($index == 2){
	//影院列表
	$time = time();
	$data = array("appKey" => $settings['movie_api_s_appKey'], "time" => $time, "cityId" => $cityid);
	$sign = $this->get_sign($data, $settings['movie_api_s_appSecret']);
	$data["sign"] = $sign;
	$url = $settings['movie_api_s_url2'] . "movieapi/movie-info/get-cinema-list";
	$res = $this->geturl($url,$data);
	if (!empty($keyword)) {
		$res["data"]['list'] = $this->cinemasearch($res["data"]['list'], $keyword);
	}
	$cinemalist = $res['data']['list'];
	foreach($cinemalist as $k => $v){
		$distance = $this->getDistance2($lon,$lat,$v['longitude'],$v['latitude']);
		$cinema[] = ['distance' => $distance,'cinemaId' =>$v['cinemaId'],'cityId' =>$v['cityId'],'cinemaName' =>$v['cinemaName'],'address' =>$v['address'],'latitude' =>$v['latitude'],'longitude' =>$v['longitude'],'phone' =>$v['phone'],'regionName' =>$v['regionName']];
	}
	$get_colum = array_column($cinema,'distance');
	array_multisort($get_colum,SORT_ASC,$cinema);

}
if($index == 3){
	$time = time();
	$data = array("appKey" => $settings['movie_api_s_appKey'], "time" => $time);
	$sign = $this->get_sign($data, $settings['movie_api_s_appSecret']);
	$data["sign"] = $sign;
	$url = $settings['movie_api_s_url'] . "movieapi/movie-info/get-soon-list";
	$res = $this->geturl($url,$data);
	if (!empty($keyword)) {
		$res["data"]['list'] = $this->search($res["data"]['list'], $keyword);
	}
	$come = $res["data"]['list'];
	foreach($come as $k=>$v){
		if(strtotime($v['publishDate'])<time()){
			$come[$k]['status'] = 1;
		}else{
			$come[$k]['status'] = 0;
		}
	}
	$come = array_slice($come,0,50);
	$comeshuliang = count($res["data"]['list']);

}

$resArr['movie'] = array("hotshuliang" => $hotshuliang, "hot" => $hot, "hotindex" => $hotindex,"comeshuliang" => $comeshuliang, "come" => $come, "cinema" => $cinema,'indexcome' => $indexcome,'indexcomeshuliang' => $indexcomeshuliang);
$ret = array();
$ret["data"] = $resArr;
$ret = json_encode($ret);
$data = array();
$data["key"] = substr(md5(time() . uniqid()), 0, 16);
$data["data"] = $this->aesEn($ret, $data["key"]);
exit(json_encode(array('code' => 0, 'status' => 1, 'msg' => 'SUCCESS', 'data' => $data)));